<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		 <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>公交站点查询</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=e06178925b8ec4746ca36a53593d07dd&plugin=AMap.StationSearch"></script>

	</head>
	<body>
<div id="container"></div>
<div id="tip"></div>
<script type="text/javascript">
    var map = new AMap.Map("container", {
        resizeEnable: true,
        center: [116.397428, 39.90923],//地图中心点
        zoom: 13 //地图显示的缩放级别
    });
	stationSearch();
    /*公交站点查询*/
    function stationSearch() {
        //实例化公交站点查询类
        var station = new AMap.StationSearch({
            pageIndex: 1, //页码
            pageSize: 60, //单页显示结果条数
            city: '010'   //确定搜索城市
        });
        station.search('东直门', function(status, result) {
            if (status === 'complete' && result.info === 'OK') {
                stationSearch_CallBack(result);
            } else {
                alert(result);
            }
        });
    }
    /*公交站点查询返回数据解析*/
    function stationSearch_CallBack(searchResult) {
        var stationArr = searchResult.stationInfo;
        var searchNum = stationArr.length;
        if (searchNum > 0) {
            document.getElementById('tip').innerHTML = '查询结果：共' + searchNum + '个站点';
            for (var i = 0; i < searchNum; i++) {
                var marker = new AMap.Marker({
                    position: stationArr[i].location,
                    map: map,
                    title: stationArr[i].name
                });
                marker.info = new AMap.InfoWindow({
                    content: stationArr[i].name,
                    offset: new AMap.Pixel(0, -30)
                });
                marker.on('click', function(e) {
                    e.target.info.open(map, e.target.getPosition())
                })
            }
            map.setFitView();
        }
    }    
</script>
<script type="text/javascript" src="http://webapi.amap.com/demos/js/liteToolbar.js"></script>
	</body>
</html>
